package com.alstudio.utils.android.media.audio.recorder;

import android.text.TextUtils;

import com.alstudio.app.ALLocalEnv;
import com.alstudio.ui.base.BaseActivity;

public class ALAudioRecordManager {

	public static void saveAudioPath(String path) {
		ALLocalEnv.getLocalEnv().getSpManager().putString("myAudioPath", path);
	}

	public static String loadAudioPath() {
		return ALLocalEnv.getLocalEnv().getSpManager().getString("myAudioPath", "");
	}

	public static void setUploadAudioState(boolean success) {
		ALLocalEnv.getLocalEnv().getSpManager().putBoolean("myAudio_upload_state", success)
				;
	}

	public static boolean isUploadAudioFailed() {
		return ALLocalEnv.getLocalEnv().getSpManager().getBoolean("myAudio_upload_state", false);
	}

	public static void setAudioLen(int len) {
		ALLocalEnv.getLocalEnv().getSpManager().putInt("myAudio_len", len);
	}

	public static int getAudioLen() {
		return ALLocalEnv.getLocalEnv().getSpManager().getInt("myAudio_len", 0);
	}

	public static boolean isLocalAudioExsit() {
		return TextUtils.isEmpty(ALLocalEnv.getLocalEnv().getSpManager().getString("myAudioPath", "")) ? false
				: true;
	}

	public static ALAudioRecordTask createAudioRecordTask(BaseActivity context,
			ALAudioRecordConfig config) {
		ALAudioRecordTask task;
		if (config != null) {
			task = new ALAudioRecordTask(context, config.getCallback());
			if (!TextUtils.isEmpty(config.getInfo())) {
				task.setSecondInfo(config.getInfo());
			}

			if (!TextUtils.isEmpty(config.getNegativeButtonName())) {
				task.setNegativeButtonName(config.getNegativeButtonName());
			}

			if (!TextUtils.isEmpty(config.getPostiveButtonName())) {
				task.setPostiveButtonName(config.getPostiveButtonName());
			}
			task.setAutoProccess(config.isAutoProccess());

		} else {
			task = new ALAudioRecordTask(context, null);
		}

		return task;
	}
}
